package com.csx.data.orm.jpa.IdGenerator;

import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

public class Segment {
    private AtomicLong value = new AtomicLong(0);
    private volatile long curMax = 0L;
    private volatile int step = 0;
    private volatile long resetMax = 0L;
    private SegmentBuffer buffer;
    private Date resetTime;// 复位时间
    private String resetCycle; //复位周期类型
    private int resetUnit; // 复位单位数


    public String getResetCycle() {
        return resetCycle;
    }

    public void setResetCycle(String resetCycle) {
        this.resetCycle = resetCycle;
    }

    public int getResetUnit() {
        return resetUnit;
    }

    public void setResetUnit(int resetUnit) {
        this.resetUnit = resetUnit;
    }

    public Date getResetTime() {
        return resetTime;
    }

    public void setResetTime(Date resetTime) {
        this.resetTime = resetTime;
    }

    public Segment(SegmentBuffer buffer) {
        this.buffer = buffer;
    }

    public AtomicLong getValue() {
        return value;
    }

    public void setValue(AtomicLong value) {
        this.value = value;
    }

    public long getCurMax() {
        return curMax;
    }

    public void setCurMax(long curMax) {
        this.curMax = curMax;
    }

    public int getStep() {
        return step;
    }

    public void setStep(int step) {
        this.step = step;
    }

    public SegmentBuffer getBuffer() {
        return buffer;
    }

    public long getIdle() {
        return this.getCurMax() - getValue().get();
    }

    public long getResetMax() {
        return resetMax;
    }

    public void setResetMax(long resetMax) {
        this.resetMax = resetMax;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Segment(");
        sb.append("value:");
        sb.append(value);
        sb.append(",max:");
        sb.append(curMax);
        sb.append(",resetMax:");
        sb.append(resetMax);
        sb.append(",resetTime:");
        sb.append(resetTime);
        sb.append(",step:");
        sb.append(step);
        sb.append(",resetCycle:");
        sb.append(resetCycle);
        sb.append(",resetUnit:");
        sb.append(resetUnit);
        sb.append(")");
        return sb.toString();
    }
}